<? include("include/session.php");

if(!$session->logged_in)
	{
		
		header("Location: notallowed.php");

	}
	
?>
<? include("functions.php");?>
<!DOCTYPE PHP>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Samenstellen - PizzaRio</title>
<link href="CSS/opmaak.css" rel="stylesheet" type="text/css">
<!--[if lte IE 7]>
<style>
.content { margin-right: -1px; } /* this 1px negative margin can be placed on any of the columns in this layout with the same corrective effect. */
ul.nav a { zoom: 1; }  /* the zoom property gives IE the hasLayout trigger it needs to correct extra whiltespace between the links */
</style>
<![endif]-->
</head>

<body>
<div class="container">
  <div class="header"> <img src="Images/Header.png"> 
    
    <!-- end .header--></div>
  <div class="nav"> <? include("nav.html");?>
  <!-- end .nav --></div>
  <div class="content1">
    <h4>Maak een nieuwe pizza of bestel een gemaakte pizza! </h4>
        <br/>
<form method="post" action="samenstellen.php">
<p><input type="submit" value="Nieuwe Pizza" /></p>
</form>
<br/>        
<form method="post" action="newpizzabestel.php">
<p><input type="submit" value="Gemaakte Pizza Bestellen" /></p>
</form>
</
<?php
// producten laten zien
$sql = "SELECT gem_pizzaID, omschrijving, prijs, pizzanaam, userid
       FROM gem_pizzas
	   WHERE gem_pizzas.userid = '".$_SESSION['username']."'
       ORDER BY pizzanaam";    // dit is dus de query om de producten op te halen
$query = mysql_query($sql) or die (mysql_error()."<br>in file ".__FILE__." on line ".__LINE__); // als de query niet uitgevoerd wordt geeft die een foutmelding met bestandsnaam en regelnummer
$num = mysql_num_rows($query);

if(empty($num)) {
  echo "<p>Er zijn geen producten gevonden.</p>\n";
} else {
  // Laat de producten zien
  while($gem_pizzas = mysql_fetch_object($query)) {
    echo "<input type=\"hidden\" name=\"gem_pizzaID\" value=\"".$gem_pizzas->gem_pizzaID."\" />\n";
	echo "<h4><strong>".$gem_pizzas->pizzanaam."</strong></h4>\n";
    echo "<p><strong>".$omschrijving."</strong><br /><br />\n";
    echo "Prijs: &euro; ".$gem_pizzas->prijs."<br /><br /></p>\n";
    echo "</form><br />\n";
  }
}
?>
<? 
	global $database;
	$q = "SELECT (Ingredienten.omschrijving) omschrijving FROM Ingredienten, Pizzaregel WHERE Pizzaregel.gem_pizzaID = ".$_SESSION['gem_pizzaID']." AND Ingredienten.ingredientID= Pizzaregel.ingredientID";
	$result = $database->query($q);
	$num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   echo "<table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n";
   for($i=0; $i<$num_rows; $i++){
	   $omschrijving= mysql_result($result,$i,"omschrijving");

      echo "<tr><td>$omschrijving</td></tr>\n";
   }
   echo "</table><br>\n";
?>
<? 
	global $database;
	$q = "SELECT sum(Ingredienten.prijs) bedrag FROM Ingredienten, Pizzaregel
			WHERE Pizzaregel.gem_pizzaID = ".$_SESSION['gem_pizzaID']." AND Ingredienten.ingredientID= Pizzaregel.ingredientID";
	$result = $database->query($q);
	$num_rows = mysql_numrows($result);
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }
   /* Display table contents */
   //echo "<table align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n";
   //echo "<tr><td><b>Totaalprijs</b></tr>\n";
   for($i=0; $i<$num_rows; $i++){
	   $totaalbedrag= mysql_result($result,$i,"bedrag");

      //echo "<tr><td>$totaalbedrag</td></tr>\n";
   }
   //echo "</table><br>\n";
     mysql_query("UPDATE `gem_pizzas` SET prijs=".$totaalbedrag."+6 WHERE gem_pizzas.gem_pizzaID=".$_SESSION['gem_pizzaID']."") or die(mysql_error());
	 //$_SESSION['totaalprijs'] = $totaalbedrag;
?>        
  <div class="footer"> <a href="index.html">
    <center>
      <p1>Home</p1>
    </center>
    </a> 
    <!-- end .footer --></div>
  <div class="footer"> <a href="overpizzario.php">
    <center>
      <p1>Over PizzaRio</p1>
    </center>
    </a> 
    <!-- end .footer --></div>
  <div class="footer"> <a href="vestigingen.php">
    <center>
      <p1>Vestigingen</p1>
    </center>
    </a> 
    <!-- end .footer --></div>
  <div class="footer"> <a href="voorwaarden.php">
    <center>
      <p1>Voorwaarden</p1>
    </center>
    </a> 
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
</html>

